package com.ctgu.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctgu.springboot.common.QueryPageParam;
import com.ctgu.springboot.entity.PubResouse;
import com.ctgu.springboot.entity.Student;
import com.ctgu.springboot.mapper.PubResouseMapper;
import com.ctgu.springboot.service.PubResouseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cs
 * @since 2023-07-07
 */
@Service
public class PubResouseServiceImpl extends ServiceImpl<PubResouseMapper, PubResouse> implements PubResouseService {

    @Resource
    private PubResouseMapper pubResouseMapper;

    @Override
    public IPage<PubResouse> listPage(QueryPageParam query) {
        Integer id = (Integer) query.getParam().get("pub_id");
        String name = (String) query.getParam().get("pub_name");
        String type = (String) query.getParam().get("pub_type");

        Page<PubResouse> page = new Page<>();
        page.setCurrent(query.getPageNum());
        page.setSize(query.getPageSize());

        LambdaQueryWrapper<PubResouse> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (id!=null) {
            lambdaQueryWrapper.like(PubResouse::getPubId, id);
        }
        if (StringUtils.isNotBlank(name) && !"null".equals(name)) {
            lambdaQueryWrapper.like(PubResouse::getPubName, name);
        }
        if (StringUtils.isNotBlank(type) && !"null".equals(type)) {
            lambdaQueryWrapper.eq(PubResouse::getPubType, type);
        }
        return pubResouseMapper.listPage(page, lambdaQueryWrapper);
    }

    public PubResouse selectByUrl(String url){
        return pubResouseMapper.selectByUrl(url);
    }
}
